package com.example.administrator.musicplay;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button1 = (Button) findViewById(R.id.button1);

        button1.setOnClickListener(startIt);
        Button button2 = (Button) findViewById(R.id.button2);
        button2.setOnClickListener(stopIt);
    }
    private View.OnClickListener startIt = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent("com.studio.android.START_AUDIO_SERVICE");
           
            intent.setPackage(getPackageName());  //在这里添加这行,表示兼容5.0之后
            startService(intent);
            //startService(new Intent("com.studio.android.START_AUDIO_SERVICE"));
        }


    };
    private View.OnClickListener stopIt = new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            Intent intent = new Intent("com.studio.android.START_AUDIO_SERVICE");

            intent.setPackage(getPackageName());  //在这里添加这行,表示兼容5.0之后
            stopService(intent);
           // stopService(new Intent("com.studio.android.START_AUDIO_SERVICE"));
            finish();
        }
    };
}
